"""
>>> from django.http import HttpRequest
>>> from django.contrib.gadgets.models import *
>>> from django.contrib.gadgets.views import gadget

# UserPrefString

>>> print UserPrefString('username').render()
<UserPref name="username" datatype="string" display_name="username"></UserPref>

# UserPrefBool

>>> print UserPrefBool('autosaving').render()
<UserPref name="autosaving" datatype="bool" display_name="autosaving" default_value="False"></UserPref>

# UserPrefEnum

>>> print UserPrefEnum('genre', enumvalues={'m':'male', 'f':'female'}).render()
<UserPref name="genre" datatype="enum" display_name="genre">
<EnumValue value="m" display_value="male"/>
<EnumValue value="f" display_value="female"/>
</UserPref>

# UserPrefHidden

>>> print UserPrefHidden('id').render()
<UserPref name="id" datatype="hidden" display_name="id"></UserPref>

# UserPrefList

>>> print UserPrefList('options', default_value=['a','b']).render()
<UserPref name="options" datatype="list" display_name="options" default_value="a|b"></UserPref>

# UserPrefLocation

>>> print UserPrefLocation('loc').render()
<UserPref name="loc" datatype="location" display_name="loc"></UserPref>

# Compatibility requirements

>>> print MayRequire('browser', 'firefox', min_version='1.5').render()
<MayRequire type="browser" value="firefox" min_version="1.5"></MayRequire>

# Feature-specific JavaScript Libraries

>>> print Require('tabs').render()
<Require feature="tabs"/>

# MessageBundle

>>> msg = MessageBundle({
...         'hello_world': 'Hello World.',
...         'color': 'Color',
...         'red': 'Red',
...         'green': 'Green',
...         'blue': 'Blue',
...         'gray': 'Gray',
...         'purple': 'Purple',
...         'black': 'Black',
...         })
>>> print msg.render()
<messagebundle>
<msg name="black">Black</msg>
<msg name="blue">Blue</msg>
<msg name="color">Color</msg>
<msg name="gray">Gray</msg>
<msg name="green">Green</msg>
<msg name="hello_world">Hello World.</msg>
<msg name="purple">Purple</msg>
<msg name="red">Red</msg>
</messagebundle>

# Locale

>>> loc = Locale('pt-br', 'BR', messages='http://domain.com/gadget/')
>>> print loc.render()
<Locale  lang="pt-br" country="BR" messages="http://domain.com/gadget/"/>

# Locale with message bundler

>>> mod = GadgetModule('Hello world!')
>>> mod.url = 'http://anotherdomain.com/gadget/'
>>> loc = Locale('en', messages=msg)
>>> loc.gadget = msg.gadget = mod
>>> print loc.render()
<Locale  lang="en" messages="http://anotherdomain.com/gadget/messages/en_ALL.xml"/>

# Module - content-type 'html'

>>> mod = GadgetModule('Hello world!')
>>> print mod.render()
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<BLANKLINE>
    <ModulePrefs >
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
    </ModulePrefs>
    <Content type="html">
        <![CDATA[
        Hello world!
        ]]>
    </Content>
</Module>

# Module - content-type 'url'

>>> mod.content_type = 'url'
>>> mod.content_href = 'http://x.com/test.html'
>>> print mod.render()
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<BLANKLINE>
    <ModulePrefs >
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
    </ModulePrefs>
    <Content type="url" href="http://x.com/test.html">
<BLANKLINE>
    </Content>
</Module>

# MyModule

>>> class MyModule(GadgetModule):
...     content_type = 'url'
...     content_href = 'http://x.com/test.html'
...     user_prefs = [UserPref('username'), UserPref('age'),]
...     mayrequires = [MayRequire('browser', 'firefox', min_version='1.5'),]
...     requires = ['tabs','grid',]
...     locales = [Locale('en', messages=MessageBundle({'name': 'Name', 'age': 'Age',}), default=True),
...                Locale('pt', country="BR", messages=MessageBundle({'name': 'Nome', 'age': 'Idade',}))]
...     url = 'http://domain.com/gadget/'

# Module with userprefs

>>> mod = MyModule()
>>> print mod.render()
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
    <UserPref name="username" datatype="string" display_name="username">
<BLANKLINE>
</UserPref>
<UserPref name="age" datatype="string" display_name="age">
<BLANKLINE>
</UserPref>
    <ModulePrefs >
        <MayRequire type="browser" value="firefox" min_version="1.5"></MayRequire>
<Require feature="tabs"/>
<Require feature="grid"/>
<Locale  lang="en" messages="http://domain.com/gadget/messages/en_ALL.xml"/>
<Locale  lang="pt" country="BR" messages="http://domain.com/gadget/messages/pt_BR.xml"/>
    </ModulePrefs>
    <Content type="url" href="http://x.com/test.html">
<BLANKLINE>
    </Content>
</Module>

# Module.get_locale

>>> loc = mod.get_locale('pt', 'BR')
>>> print loc.render()
<Locale  lang="pt" country="BR" messages="http://domain.com/gadget/messages/pt_BR.xml"/>

# View root path

>>> req = HttpRequest()
>>> #gadget(req, '', MyModule)

# View message path

>>> req = HttpRequest()
>>> #gadget(req, 'messages/en_ALL.xml', MyModule)

# urlpatterns = patterns('',
#    # Example:
#
#    (r'^versos/(?P<path>.*)$', 'django.contrib.gadgets.views.gadget', {'module': VersosModule}),
#)

# Prototype design pattern style on UserPref, Locale and MayRequire objects

>>> mod2 = MyModule()
>>> id(mod2) == id(mod)
False

>>> id(mod2.user_prefs[0]) == id(mod.user_prefs[0])
False

>>> id(mod2.mayrequires[0]) == id(mod.mayrequires[0])
False

>>> id(mod2.locales[0]) == id(mod.locales[0])
False

"""

if __name__ == '__main__':
    import doctest
    doctest.testmod()
